from openpyxl import load_workbook

class Write2Excel:


    def __init__(self,excel_filename, sheet_name):
        self.excel_filename = excel_filename
        self.book = load_workbook(filename=excel_filename,read_only=False)
        self.sheet = self.book.get_sheet_by_name(sheet_name)
    """
    column_index             = C
    row_index                = 9
    column_index + row_index = C9
    """
    def write(self ,content, row_index, column_index) :
        self.sheet[column_index+row_index] = content

    def write(self ,content, cell_name) :
            if self.sheet[cell_name].value:
                self.sheet[cell_name] = self.sheet[cell_name].value+"\n"+content
            else:
                self.sheet[cell_name] =content

            self.book.save(self.excel_filename)

    def read(self, cell_name) :
          return self.sheet[cell_name].value

